﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using cbmobile.BLC;
using cbmobile.DAC;
using PQT.Common;
using PQT.Controls;
using PQT.API.File;
using PQT.API.DataDefine.Sys;
using PQT.API;

namespace cbmobile.MasterUser.UC_user
{
    public partial class News_List : PQT.API.CommonUserControl
    {
        BLC_TinTuc nBLC = new BLC_TinTuc();
        int pageSize = 4;

        private int CurrentPage
        {
            get 
            {
                if (ViewState["g_CurrentPage"] != null)
                    return Convert.ToInt32(ViewState["g_CurrentPage"]);
                return 1;
            }
            set 
            {
                ViewState["g_CurrentPage"] = value;
            }
        }

        public string UK
        {
            get;
            set;
        }

        public int NewsCatID
        {
            get
            {
                return Helper.ValidateParam("cID", 0);
            }
        }

        protected string TrimText(object p_content, int p_num)
        {
            string content = p_content.ToString();
            if (content.Length > p_num)
            {
                content = content.Substring(0, p_num) + "...";
            }
            return content;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            BindNews();
        }

        private void BindNews()
        {
            DataTable dt = nBLC.Get_News();
            rptNews.DataSource = dt;
            rptNews.DataBind();

            int recordCount = nBLC.GetTotalRecord("");
            PQTPager1.RecordCount = recordCount;

            if (recordCount > 0)
            {
                PQTPager1.PageSize = pageSize;
                PQTPager1.PagerButtonCount = 5;
                PQTPager1.CurrentPageIndex = this.CurrentPage - 1;
            }
        }

        protected void PQTPager1_PageIndexChanged(object sender, PageIndexChangedEventArgs e)
        {
            this.CurrentPage = e.NewPageIndex + 1;
            BindNews();
        }

    }
}